/*
 * Class representing a book of a library
 * @author M.T. Segarra
 * @version 0.0.1
 */
package booksManagement;


import java.util.*;

import exceptions.*;

import javax.persistence.*;

import loansManagement.Loan;

/**
 * Entity implementation class for Entity: Book
 *
 */
@Entity
@DiscriminatorValue("Book")
@NamedQuery(name="findAllBooks", query="select b from Book b")
public class Book extends mediasManagement.Media implements java.io.Serializable {
	
	// Fields
	/**
	 * @uml.property name="authors"
	 */
	@Transient
	private ArrayList<String> authors;
	
	
	
	/**
	 * Getter of the property <tt>authors</tt>
	 *
	 * @return Returns the authors.
	 * @uml.property name="authors"
	 */
	public ArrayList<String> getAuthors() {
		return authors;
	}

	/**
	 * Setter of the property <tt>authors</tt>
	 *
	 * @param authors
	 *            The authors to set.
	 * @uml.property name="authors"
	 */
	public void setAuthors(ArrayList<String> authors) {
		this.authors = authors;
	}

	/*
	 * Two books are equal if their ISBN is the same
	 */
	@Override
	public boolean equals(Object book) {
		if (book == null)
			return false;
		Book b = (Book) book;

		if (b.isbnOrIsan == isbnOrIsan)
			return true;

		return false;
	}

	public Book(){};


	/**
	 * Creates a book All parameters should be given
	 *
	 * @param title
	 *            the title of the book
	 * @param authors
	 *            the list of the authors (names)
	 * @param editionDate
	 *            date of the edition of the book
	 * @param isbn
	 *            ISBN of the book
	 * @throws BadParametersException
	 * @throws MediaExistsException 
	 */
	public Book(String title, Calendar editionDate, 
			java.lang.String isbnOrIsan, Integer specimens, ArrayList<String> authors) throws BadParametersException, MediaExistsException {
		super(title, editionDate, "Book", isbnOrIsan, specimens);
		if (authors == null)
			throw new BadParametersException();
		this.authors = authors;
	}

}

